#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-09-03 16:52:28
# Project: douban
from sqlalchemy.orm import sessionmaker
from db.sqlacmy.SQLAlchemyEntity import engine, User, Article

Session = sessionmaker(bind=engine)
session = Session()

a = session.query(User).get(2)
outStr = "userName:%s -> (password: %s,email: %s)" % (a.username, a.password, a.email)
print(outStr)

a = session.query(User).filter_by(username='Sandra Zavala').first()
outStr = "userName:%s -> (password: %s,email: %s)" % (a.username, a.password, a.email)
print(outStr)

a = session.query(User).filter(User.username == 'Vanessa Schneider', User.email == 'igriffin@yahoo.com').first()
outStr = "userName:%s -> (password: %s,email: %s)" % (a.username, a.password, a.email)
print(outStr)

print("\n\n\n")

a = session.query(User).all()
for e in a:
    outStr = "userName:%s -> (password: %s,email: %s)" % (e.username, e.password, e.email)
    print(outStr)



print("\n\n\n")
print("like:\n")
a = session.query(User).filter(User.username.like('K%'))
for e in a:
    outStr = "userName:%s -> (password: %s,email: %s)" % (e.username, e.password, e.email)
    print (outStr)



print("\n\n\n")
print("like3:")
a = session.query(User).filter(User.username.like('K%'))
lst = [e for e in a if e.email[0]=='b']

for l in lst:
    outStr = "userName:%s -> (password: %s,email: %s)" % (l.username, l.password, l.email)
    print (outStr)


print("\n\n\n")
a = session.query(Article).get(10)
print (a)
print (a.tags)
print (a.cate_id)
print (a.category)
print (a.title)